﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace WCS.Infrastructure.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class InitialCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AccountTransaction",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "账户交易记录ID"),
                    TransactionNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "账户交易编号"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "关联用户ID"),
                    Amount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "变动金额（正数=增加，负数=减少）"),
                    BalanceAfter = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "变动后余额"),
                    TransactionType = table.Column<int>(type: "integer", nullable: false, comment: "账户交易记录类型：1=分账收入,2=订单退款,3=余额提现,4=结算转入可提现,5=手动转账,6=优惠券互推,10=订单手续费,11=提现手续费,12=优惠券服务费"),
                    TransactionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "交易时间"),
                    Remark = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "交易备注（如：退款冻结，结算T+1）"),
                    BalanceType = table.Column<int>(type: "integer", nullable: true, comment: "变动的余额类型(1=可用余额,2=冻结余额,3=可提现余额,4=未结算余额,5=待分账余额)"),
                    OrderId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "订单ID"),
                    DividedRecordDetailId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "分账记录详情ID"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    WithdrawalRecordId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "提现记录ID"),
                    PaymentPlatformId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付平台ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("AccountTransaction_pkey", x => x.Id);
                },
                comment: "账户交易记录表");

            migrationBuilder.CreateTable(
                name: "ActionLog",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "行为日志ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户ID"),
                    Type = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "类型"),
                    Action = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "行为"),
                    Version = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "记录版本"),
                    ApiUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "本次请求的接口地址"),
                    IP = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "请求IP"),
                    Params = table.Column<string>(type: "text", nullable: true, comment: "请求参数"),
                    Result = table.Column<int>(type: "integer", nullable: true, comment: "结果"),
                    ResultMessage = table.Column<string>(type: "text", nullable: true, comment: "结果信息"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("ActionLog_pkey", x => x.Id);
                },
                comment: "行为日志表");

            migrationBuilder.CreateTable(
                name: "CouponConsumptionRecord",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "核销记录ID"),
                    CouponInstanceId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联优惠券实例ID"),
                    OrderId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联订单ID"),
                    ConsumptionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "核销时间"),
                    ConsumptionType = table.Column<int>(type: "integer", nullable: true, comment: "核销方式：1=线下POS扫码核销，2=线上支付自动核销，3=小程序手动选择核销，4=API接口核销，5=客服手动核销，6=系统自动核销（满足条件时）"),
                    ConsumptionCodeId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "核销收款码ID"),
                    ConsumptionDevice = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "核销设备信息"),
                    ConsumptionIp = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: true, comment: "核销IP地址"),
                    IsCanceled = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否已撤销（true=核销后因退款等原因撤销，false=正常核销）"),
                    CancelTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "撤销时间（若撤销，记录撤销的时间）"),
                    CancelReason = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "撤销原因（如“用户退款”“核销错误”等）"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("CouponConsumptionRecord_pkey", x => x.Id);
                },
                comment: "优惠券核销记录表");

            migrationBuilder.CreateTable(
                name: "CouponInstance",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "优惠券实例ID"),
                    InstanceCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "优惠券实例编号"),
                    TemplateId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联模板ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "领取用户ID"),
                    AvailableStartTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "可使用开始时间：由模板的生效延迟类型（EffectiveDelayType）与有效期类型（ValidityType）组合计算；当有效期为固定范围（ValidityType=1）时，取 Max(延迟生效时间, 模板固定有效期开始时间)；当有效期为相对时长（ValidityType=2）时，取延迟生效后的时间点作为开始时间。"),
                    AvailableEndTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "可使用结束时间：当有效期为固定范围（ValidityType=1）时，取模板固定有效期结束时间；当有效期为相对时长（ValidityType=2）时，取 AvailableStartTime + 模板有效期时长（小时）。"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发控制标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    Status = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "状态：0=未激活，1=未使用，2=已使用，3=已过期，4=已冻结"),
                    RecommendMerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "推荐商户ID"),
                    UnionId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "用户在同一微信开放平台账号下所有应用（包括小程序、公众号等）的全局唯一标识"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "所属商户ID"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "所属门店ID"),
                    CodeId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "所属收款码ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("CouponInstance_pkey", x => x.Id);
                },
                comment: "优惠券实例表");

            migrationBuilder.CreateTable(
                name: "CouponPackage",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "优惠券包ID"),
                    PackageCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "优惠券包编号"),
                    Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "优惠券包名称"),
                    Description = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "优惠券包描述"),
                    QRCodeUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "优惠券包二维码图片地址"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "归属商家ID（平台）"),
                    StartTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "券包生效时间"),
                    EndTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "券包失效时间"),
                    Status = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "券包状态：1=草稿（未发布），2=已发布（可领取），3=已停用（停止领取）"),
                    IssueCount = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "总领取次数"),
                    UsedCount = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "已使用次数"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建人ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改人ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, comment: "启用状态")
                },
                constraints: table =>
                {
                    table.PrimaryKey("CouponPackage_pkey", x => x.Id);
                },
                comment: "优惠券包表");

            migrationBuilder.CreateTable(
                name: "CouponPackageItem",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "优惠券包关联ID"),
                    PackageId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联优惠券包ID"),
                    TemplateId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联优惠券模板ID"),
                    Quantity = table.Column<int>(type: "integer", nullable: true, defaultValue: 1, comment: "每个用户可领取的数量（默认1）"),
                    Sort = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "排序号（券包内优惠券的展示顺序，数字越小越靠前）"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("CouponPackageItem_pkey", x => x.Id);
                },
                comment: "优惠券包关联表");

            migrationBuilder.CreateTable(
                name: "CouponPackageReceiveRecord",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "记录ID"),
                    PackageId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联优惠券包ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "领取用户ID"),
                    ReceiveChannel = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "领取渠道：1=线下扫码，2=线上推荐（小程序），3=活动页面"),
                    ReceiveCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "领取凭证（如扫码的凭证码）"),
                    DeviceInfo = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "领取设备信息（如手机型号）"),
                    IPAddress = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: true, comment: "领取IP地址"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("CouponPackageReceiveRecord_pkey", x => x.Id);
                },
                comment: "优惠券包领取记录表");

            migrationBuilder.CreateTable(
                name: "CouponTemplate",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "优惠券模板ID"),
                    TemplateCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "优惠券模板编号"),
                    Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "优惠券名称"),
                    SchemeType = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "方案类型：0=非消费券，1=消费者承担服务费，2=商家承担服务费"),
                    CouponType = table.Column<int>(type: "integer", nullable: false, comment: "优惠券类型：1=减免券，2=折扣券，3=礼品券"),
                    DiscountAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "优惠金额"),
                    Discount = table.Column<decimal>(type: "numeric", nullable: true, defaultValueSql: "0", comment: "优惠折扣"),
                    UseThresholdAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "使用门槛金额"),
                    PlatformServiceFeeRate = table.Column<decimal>(type: "numeric", nullable: true, defaultValueSql: "0", comment: "平台服务费率（3%-5%）"),
                    ReceiveStartTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "领取开始时间（用户可领取该优惠券的起始时间）"),
                    ReceiveEndTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "领取结束时间（用户可领取该优惠券的截止时间，超出则无法领取）"),
                    ValidityType = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "有效期类型：1=固定时间范围（所有券统一可用时间），2=领取后N小时内可用"),
                    ValidityStartTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "固定有效期的开始时间（当ValidityType=1时必填）"),
                    ValidityEndTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "固定有效期的结束时间（当ValidityType=1时必填）"),
                    ValidityDuration = table.Column<int>(type: "integer", nullable: true, comment: "有效期时长（ValidityType=2时必填，单位：小时）"),
                    EffectiveDelayType = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "生效延迟类型：0=领取后立即生效，1=次日0点生效，2=领取后N小时生效"),
                    EffectiveDelayValue = table.Column<int>(type: "integer", nullable: true, comment: "生效延迟值（当EffectiveDelayType=2时必填，单位：小时）"),
                    UseFrequencyType = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "使用频率限制：1=无限制，2=每日，3=每周"),
                    UseFrequencyLimit = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "每个周期内最大使用次数（如每日限用1次则填1）"),
                    Total = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "总数量"),
                    UsedCount = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "已使用数量"),
                    MaxIssuePerUser = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "每人最多领取数量"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "所属商户ID"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "所属门店ID"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发控制标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建人ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改人ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除人ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "模板启用状态：0=禁用,1=启用"),
                    CodeId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "所属收款码ID"),
                    PosterUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "海报地址"),
                    QuantityIssued = table.Column<int>(type: "integer", nullable: true, comment: "发放数量")
                },
                constraints: table =>
                {
                    table.PrimaryKey("CouponTemplate_pkey", x => x.Id);
                },
                comment: "优惠券模板表");

            migrationBuilder.CreateTable(
                name: "DividedAgreement",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账协议ID"),
                    AgreementCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账协议编号"),
                    AgreementName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "分账协议名称"),
                    ParentAgreementId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "父级协议ID"),
                    StartTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "生效时间"),
                    EndTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "失效时间（为空为长期有效）"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建人ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改人ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "启用状态(0=禁用，1=启用，用户设置)"),
                    ActivationStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "激活状态(0=未激活，1=已激活，系统判断)"),
                    DividedCycle = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "分账周期"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "所属商户ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Agreement_pkey", x => x.Id);
                },
                comment: "分账协议表");

            migrationBuilder.CreateTable(
                name: "DividedAgreementDetail",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账协议详情ID"),
                    DividedAgreementId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账协议ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户ID"),
                    Ratio = table.Column<decimal>(type: "numeric", nullable: true, defaultValueSql: "0", comment: "分账比例"),
                    IsMasterAccount = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否是主账户"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    ActivationStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "激活状态(0=未激活，1=已激活，用户确认后激活)"),
                    UserRoleId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户角色ID"),
                    SubAgreementId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "子协议ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("SharingAgreementUser_pkey", x => x.Id);
                },
                comment: "分账协议详情表");

            migrationBuilder.CreateTable(
                name: "DividedRecord",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账记录ID"),
                    RecordNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账记录编号"),
                    OrderId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联订单ID"),
                    CodeId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "收款码ID"),
                    DividedAgreementId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账协议ID"),
                    TotalDividedAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "分账总金额"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "商户ID"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建者ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "修改者ID"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "门店ID"),
                    DividedDate = table.Column<DateTime>(type: "timestamp(0) without time zone", nullable: false, comment: "分账日期")
                },
                constraints: table =>
                {
                    table.PrimaryKey("DividedRecord_pkey", x => x.Id);
                },
                comment: "分账记录表");

            migrationBuilder.CreateTable(
                name: "DividedRecordDetail",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账记录详情ID"),
                    DividedRecordId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账记录ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账接收方用户ID"),
                    Ratio = table.Column<decimal>(type: "numeric", nullable: false, comment: "分账比例"),
                    DividedAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "分账金额"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    EntryTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "入账时间"),
                    IsEntry = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否入账"),
                    IsMasterAccount = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否是主账户"),
                    RootAgreementId = table.Column<string>(type: "text", nullable: true),
                    LayerAgreementId = table.Column<string>(type: "text", nullable: true),
                    PathJson = table.Column<string>(type: "text", nullable: true),
                    PathDepth = table.Column<int>(type: "integer", nullable: true),
                    PathAgreementCount = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("DividedRecordDetail_pkey", x => x.Id);
                },
                comment: "分账记录详情表");

            migrationBuilder.CreateTable(
                name: "EpaylinksSplitRecord",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账记录ID"),
                    OutTradeNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "商户订单号（分账订单号）"),
                    CustomerCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户编号"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "用户ID"),
                    Amount = table.Column<long>(type: "bigint", nullable: false, comment: "分账金额，单位为分"),
                    Fee = table.Column<long>(type: "bigint", nullable: false, comment: "手续费，单位为分"),
                    ActualAmount = table.Column<long>(type: "bigint", nullable: false, comment: "实际提现金额，单位为分"),
                    FeeRate = table.Column<decimal>(type: "numeric", nullable: false, comment: "费率"),
                    SplitStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "分账状态：0=处理中,1=分账成功,2=分账失败,3=预分帐成功，4=已撤销，5=待处理"),
                    TransactionNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "易票联订单号"),
                    SplitTransactionNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "易票联分账单号"),
                    OutSplitTradeNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "商户分账单号"),
                    RevokeTransactionNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "撤销单号"),
                    RealAmount = table.Column<long>(type: "bigint", nullable: true, comment: "实际分账金额"),
                    SplitState = table.Column<string>(type: "character varying(2)", maxLength: 2, nullable: true, comment: "分账结果（00=分账成功，01=分账失败，03=处理中，04=预分帐成功，05=已撤销，51=待处理）"),
                    RequestTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "分账请求时间"),
                    SplitTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "分账完成时间"),
                    CallbackTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "回调接收时间"),
                    RequestData = table.Column<string>(type: "jsonb", nullable: true, comment: "请求参数JSON"),
                    CallbackData = table.Column<string>(type: "jsonb", nullable: true, comment: "回调参数JSON"),
                    ApiResponse = table.Column<string>(type: "jsonb", nullable: true, comment: "请求后响应JSON"),
                    AttachData = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "商户备注"),
                    NotifyUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "通知地址"),
                    NonceStr = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "随机字符串"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    ProcedureFee = table.Column<long>(type: "bigint", nullable: true, comment: "分账手续费（单位为分）"),
                    MemberId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "分账商户编号")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EpaylinksSplitRecord", x => x.Id);
                },
                comment: "易票联分账记录表");

            migrationBuilder.CreateTable(
                name: "ErrorLog",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "错误日志ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户ID"),
                    Message = table.Column<string>(type: "text", nullable: true, comment: "错误消息"),
                    Api = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "引发错误的接口地址"),
                    IP = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "请求IP"),
                    Params = table.Column<string>(type: "text", nullable: true, comment: "本次请求的参数"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("ErrorLog_pkey", x => x.Id);
                },
                comment: "错误日志表");

            migrationBuilder.CreateTable(
                name: "LoginLog",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "登录日志ID"),
                    Account = table.Column<string>(type: "character varying(11)", maxLength: 11, nullable: true, comment: "用户账户"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户Id"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(0) without time zone", nullable: true, comment: "登录时间"),
                    Result = table.Column<int>(type: "integer", nullable: true, comment: "结果"),
                    IP = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "登录IP"),
                    Code = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "凭据"),
                    Type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true, comment: "类型"),
                    Explain = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "描述")
                },
                constraints: table =>
                {
                    table.PrimaryKey("LoginLog_pkey", x => x.Id);
                },
                comment: "登录日志表");

            migrationBuilder.CreateTable(
                name: "Merchant",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户ID"),
                    MerchantCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户编号"),
                    Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "商户名称"),
                    Address = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "商户地址"),
                    DetailedAddress = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "商户详细地址"),
                    ContactPerson = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "联系人名称"),
                    ContactPhone = table.Column<string>(type: "character varying(11)", maxLength: 11, nullable: false, comment: "联系电话"),
                    MerchantType = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "商户类型"),
                    SettlementCycle = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "结算周期"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建人ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改者ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "启用状态"),
                    Business = table.Column<string>(type: "jsonb", nullable: true, comment: "业务开通信息"),
                    AcqSpId = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "平台商户编号"),
                    AcqMerId = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "商户编号"),
                    MerId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true, comment: "商户侧唯一标识"),
                    BackUrl = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true, comment: "审核结果通知地址"),
                    Paper = table.Column<string>(type: "jsonb", nullable: true, comment: "商户详细信息"),
                    AcceptOrder = table.Column<int>(type: "integer", nullable: true, comment: "是否收单"),
                    BusinessBackUrl = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true, comment: "业务启停回调地址"),
                    Version = table.Column<string>(type: "character varying(5)", maxLength: 5, nullable: true, comment: "版本号"),
                    MerchantName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "商户名称"),
                    AccountStatus = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "账户状态（0：未开通，1：已开通，2：冻结；3：注销；4：止付；5：禁止入金）"),
                    AuditStatus = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "审核状态（1：待审核; 2：审核通过; 3：审核未通\r\n过）"),
                    AuditMsg = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "审核说明"),
                    AuditTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true, comment: "审核时间"),
                    Location = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "经纬度"),
                    PaymentPlatformId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付平台ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Merchant_pkey", x => x.Id);
                },
                comment: "商户表");

            migrationBuilder.CreateTable(
                name: "Order",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "订单ID"),
                    OrderCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "订单编号"),
                    OrderAmount = table.Column<long>(type: "bigint", nullable: false, comment: "订单金额"),
                    OrderType = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "订单类型"),
                    CodeId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "收款码ID"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "门店ID"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户ID"),
                    DeviceId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付设备ID"),
                    Rate = table.Column<decimal>(type: "numeric", nullable: false, comment: "费率"),
                    Commission = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "手续费"),
                    CouponInstanceId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "优惠券实例ID"),
                    DiscountAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "优惠金额"),
                    SettlementAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "结算金额"),
                    PlatformServiceFeeRate = table.Column<decimal>(type: "numeric", nullable: true, defaultValueSql: "0", comment: "平台服务费率（优惠券使用产生）"),
                    PlatformServiceFee = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "平台服务费（优惠券使用产生）"),
                    RecommendationCommissionAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "优惠券推荐抽成金额"),
                    RecommendMerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "推荐商户ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付用户ID"),
                    DividedAgreementId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "分账协议ID"),
                    OrderSnapshot = table.Column<string>(type: "jsonb", nullable: true, comment: "订单快照"),
                    TotalRefundAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "累计退款金额"),
                    RefundCount = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "退款次数"),
                    RefundStatus = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "退款结果状态(0=未退款,1=部分退款,2=全额退款)"),
                    LastRefundTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后退款时间"),
                    IsSettlement = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "是否结算"),
                    SettlementDate = table.Column<DateTime>(type: "timestamp(0) without time zone", nullable: false, comment: "结算日期(根据结算周期算出 只取日期部分 时间为 00:00:00)"),
                    SettlementTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "结算时间"),
                    IsDivided = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "是否分账"),
                    DividedDate = table.Column<DateTime>(type: "timestamp(0) without time zone", nullable: false, comment: "分账日期(根据分账周期算出 只取日期部分 时间为 00:00:00)"),
                    DividedTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "分账时间"),
                    Version = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "版本号"),
                    OutTradeNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户订单号"),
                    CustomerCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户编号"),
                    ClientIp = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true, comment: "用户终端 IP"),
                    OrderInfo = table.Column<string>(type: "jsonb", nullable: true, comment: "商品订单信息"),
                    PayAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "支付金额，单位为分"),
                    PayCurrency = table.Column<string>(type: "character varying(5)", maxLength: 5, nullable: false, comment: "支付币种：默讣CNY人民币 "),
                    NoCreditCards = table.Column<string>(type: "character varying(5)", maxLength: 5, nullable: true, comment: "是否禁止信用卡支付"),
                    NotifyUrl = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "支付结果通知地址"),
                    RedirectUrl = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "商户支付结果展示地址"),
                    AttachData = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true, comment: "商户备注"),
                    TransactionStartTime = table.Column<string>(type: "character varying(14)", maxLength: 14, nullable: false, comment: "交易开始时间"),
                    TransactionEndTime = table.Column<string>(type: "character varying(14)", maxLength: 14, nullable: true, comment: "交易超时时间"),
                    PayMethod = table.Column<string>(type: "character varying(4)", maxLength: 4, nullable: true, comment: "支付方式"),
                    SubAppId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "子商户公众号appid"),
                    ChannelMchtNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "上游商户号"),
                    EnablePayChannels = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true, comment: "分期可用渠道"),
                    InstalmentsNum = table.Column<int>(type: "integer", nullable: true, comment: "分期期数"),
                    AlipayStoreCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付宝门店编号"),
                    AlipayStoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付宝门店ID"),
                    ExtUserInfo = table.Column<string>(type: "jsonb", nullable: true, comment: "付款人信息（微信、支付宝支付时有效）"),
                    TerminalInfo = table.Column<string>(type: "jsonb", nullable: true, comment: "终端信息"),
                    AreaInfo = table.Column<string>(type: "character varying(6)", maxLength: 6, nullable: false, comment: "地区信息"),
                    ExtendParams = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "扩展参数"),
                    Coupons = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true, comment: "优惠编码"),
                    NonceStr = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "随机字符串"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建人ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改者ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    CashAmount = table.Column<long>(type: "bigint", nullable: true, comment: "应结订单金额，单位分，可选参数。"),
                    CouponAmount = table.Column<long>(type: "bigint", nullable: true, comment: "代金券金额，单位分，可选参数。"),
                    CouponDetails = table.Column<string>(type: "text", nullable: true, comment: "优惠信息，使用优惠券时必须，参考 couponDetails 说明。"),
                    IpInfo = table.Column<string>(type: "text", nullable: true, comment: "分期信息，JSON 对象，分期支付时必填，参考“分期 IPInfo 对象”。"),
                    IpProtocolVersion = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true, comment: "分期协议版本号，分期必需。"),
                    Irr = table.Column<float>(type: "real", nullable: true, comment: "签约折算年化利率，分期必需，详见年化内部收益率（IRR）计算公式，百分比数字，保留两位小数，示例：15.18%年化率取值：15.18。"),
                    IrrType = table.Column<int>(type: "integer", nullable: true, comment: "年化利率计费方式，分期必需，1：单利，2：复利。"),
                    PayServiceCharged = table.Column<long>(type: "bigint", nullable: true, comment: "支付服务费，单位分"),
                    PaymentTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "支付完成时间"),
                    PaymentStatus = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "支付状态(0=处理中，1=支付成功​，2=支付失败​​，3=已撤销，4=已关闭，5=已超时​​)"),
                    ProcedureFee = table.Column<long>(type: "bigint", nullable: true, comment: "手续费，交易过程中产生的手续费用"),
                    Remark = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "交易说明，长度为 100 位的字符串，可选参数。"),
                    Reserved = table.Column<string>(type: "character varying(400)", maxLength: 400, nullable: true, comment: "保留信息，长度为 400 位的字符串，参考“reserved 字段说明”，可选参数。"),
                    ChannelOrder = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "上游订单号"),
                    TerminalName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "终端名称"),
                    TerminalNo = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "终端号"),
                    TransactionNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "易票联订单号"),
                    BuyerId = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true, comment: "买家的支付宝唯一用户号，长度为 28 位的字符串，支付宝类交易需要返回，2088 开头的 16 位纯数字。"),
                    BuyerLogonId = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "买家的支付宝账号，长度为 100 位的字符串，支付宝类交易需要返回。"),
                    NfcTagId = table.Column<string>(type: "character varying(14)", maxLength: 14, nullable: true, comment: "标签 ID，长度为 14 位的字符串，碰一碰类型交易返回。"),
                    OpenId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户在 appId 下的唯一标识，长度为 32 位的字符串，微信类交易需要返回。"),
                    SubOpenId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户在子商户 appId 下的唯一标识，长度为 32 位的字符串，微信类交易需要返回。"),
                    RefundableAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "可退款金额（实收金额 - 累计退款金额）"),
                    RefundProcessStatus = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "退款处理状态(0=无退款进行中,1=退款处理中)")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AiCollection_Orders", x => x.Id);
                },
                comment: "订单表");

            migrationBuilder.CreateTable(
                name: "OrderRefundRecord",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "订单退款ID"),
                    OrderId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "订单ID"),
                    CustomerCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户编号"),
                    OutRefundNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "商户退款单号（退款单号，代表本次退款申请交易）"),
                    OutTradeNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户订单号"),
                    TransactionNo = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "易票联订单号"),
                    OutSplitTradeNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "商户分账单号（拆单分账时有效）"),
                    RefundAmount = table.Column<long>(type: "bigint", nullable: false, comment: "申请退款金额（单位分）"),
                    OriginalAmount = table.Column<long>(type: "bigint", nullable: false, comment: "原订单金额（单位分）"),
                    OrderInfo = table.Column<string>(type: "jsonb", nullable: true, comment: "商品订单信息"),
                    Remark = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, comment: "退款申请说明"),
                    NotifyUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "退款结果通知地址"),
                    SplitInfoList = table.Column<string>(type: "jsonb", nullable: true, comment: "分账退款信息列表（JSON格式）"),
                    ReturnToList = table.Column<string>(type: "jsonb", nullable: true, comment: "退款路径（JSON格式）"),
                    NonceStr = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "随机字符串"),
                    ProcedureFee = table.Column<long>(type: "bigint", nullable: true, comment: "退款手续费（单位分）"),
                    BackpayProcedurefee = table.Column<long>(type: "bigint", nullable: true, comment: "退回收单手续费（单位分）"),
                    BackSplitProcedureFee = table.Column<long>(type: "bigint", nullable: true, comment: "退回分账手续费（单位分）"),
                    ChannelTradeNo = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "上游订单号"),
                    RefundState = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true, comment: "退款执行结果"),
                    RefundDetail = table.Column<string>(type: "jsonb", nullable: true, comment: "优惠退款详情（JSON格式）"),
                    Reserved = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, comment: "保留信息"),
                    RefundTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "退款时间"),
                    RefundReason = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "退款原因"),
                    Status = table.Column<int>(type: "integer", nullable: false, comment: "状态（0=处理中，1=成功，2=失败）"),
                    IsAutoRefund = table.Column<bool>(type: "boolean", nullable: false, comment: "是否全额退款"),
                    Version = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "版本号"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    RequestData = table.Column<string>(type: "jsonb", nullable: true, comment: "请求参数JSON（记录完整的退款请求参数）"),
                    CallbackData = table.Column<string>(type: "jsonb", nullable: true, comment: "回调参数JSON（记录退款回调数据）"),
                    ApiResponse = table.Column<string>(type: "jsonb", nullable: true, comment: "API响应JSON（记录退款接口响应数据）"),
                    ExtraProperties = table.Column<string>(type: "jsonb", nullable: true, comment: "扩展属性")
                },
                constraints: table =>
                {
                    table.PrimaryKey("OrderRefundRecord_pkey", x => x.Id);
                },
                comment: "订单退款记录表");

            migrationBuilder.CreateTable(
                name: "PaymentCode",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "支付码ID"),
                    Code = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "支付码编号"),
                    CodeName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "支付码名称"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户ID"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "门店ID"),
                    DividedAgreementId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "分账协议ID"),
                    ParentId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "父级支付码ID"),
                    DeviceId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付设备ID"),
                    SettlementCycle = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "结算周期"),
                    CascadeId = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true, comment: "级联ID，用于多级关联"),
                    CodeUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "支付码URL"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建者ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改者ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "启用状态")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AiCollection_PaymentCodes", x => x.Id);
                },
                comment: "支付码表");

            migrationBuilder.CreateTable(
                name: "PaymentDevices",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "支付设备编号"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "门店ID"),
                    DeviceCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "设备编码"),
                    SerialNumber = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "序列号"),
                    Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "设备名称"),
                    DeviceType = table.Column<int>(type: "integer", nullable: false, comment: "设备类型"),
                    DeviceStatus = table.Column<int>(type: "integer", nullable: false, comment: "设备状态"),
                    PurchaseTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "购买时间"),
                    WarrantyExpirationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "保修截止时间"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建者ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改者ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "启用状态")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AiCollection_PaymentDevices", x => x.Id);
                },
                comment: "支付设备表");

            migrationBuilder.CreateTable(
                name: "PaymentPlatforms",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "支付平台ID"),
                    Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "名称"),
                    Description = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true, comment: "备注"),
                    Code = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "平台编号"),
                    AcceptOrder = table.Column<bool>(type: "boolean", nullable: true, comment: "是否接单"),
                    AcqSpId = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "收单服务商ID"),
                    AppId = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "应用ID"),
                    CallbackUrl = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, comment: "回调URL"),
                    SecretKey = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "密钥"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建者ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "修改者ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "启用状态"),
                    ActivationStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "激活状态"),
                    CascadeId = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true, comment: "级联ID"),
                    ApproveMessage = table.Column<string>(type: "character varying(400)", maxLength: 400, nullable: true, comment: "审核消息"),
                    EpaylinksApprovedTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks审核通过时间"),
                    EpaylinksAuditNotificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks审核通知时间"),
                    EpaylinksBusinessNotificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks业务通知时间"),
                    EpaylinksFirstApplyTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks首次申请时间"),
                    EpaylinksLastApplyTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks最后申请时间"),
                    MerchantType = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "商户类型"),
                    Balance = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "账户余额"),
                    VirtualBalance = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "虚拟余额"),
                    WithdrawableBalance = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "可提现余额"),
                    WithdrawalMethod = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "提现方式"),
                    UnsettledBalance = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "未结算余额")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AiCollection_PaymentPlatforms", x => x.Id);
                },
                comment: "支付平台表");

            migrationBuilder.CreateTable(
                name: "RateConfig",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "费率配置ID"),
                    RateName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false, comment: "费率名称"),
                    RateType = table.Column<int>(type: "integer", nullable: false, comment: "费率类型：1=支付费率,2=提现费率,3=分账费率,4=退款费率"),
                    BusinessType = table.Column<int>(type: "integer", nullable: false, comment: "业务类型：1=微信支付,2=支付宝,3=银行卡,4=现金,5=其他"),
                    RateValue = table.Column<decimal>(type: "numeric", nullable: false, comment: "费率值（小数形式，如0.006表示0.6%）"),
                    MinFee = table.Column<long>(type: "bigint", nullable: true, comment: "最低费用（单位：分）"),
                    MaxFee = table.Column<long>(type: "bigint", nullable: true, comment: "最高费用（单位：分）"),
                    AmountRangeStart = table.Column<long>(type: "bigint", nullable: true, comment: "金额区间起始值（单位：分，null表示无限制）"),
                    AmountRangeEnd = table.Column<long>(type: "bigint", nullable: true, comment: "金额区间结束值（单位：分，null表示无限制）"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "商户ID（null表示全局费率）"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "门店ID（null表示商户级费率）"),
                    PaymentPlatformId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "支付平台ID（null表示通用费率）"),
                    EffectiveTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "生效时间"),
                    ExpiryTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "失效时间（null表示永久有效）"),
                    Priority = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "优先级（数值越大优先级越高）"),
                    Remark = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true, comment: "备注说明"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建者ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改者ID"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "启用状态")
                },
                constraints: table =>
                {
                    table.PrimaryKey("RateConfig_pkey", x => x.Id);
                },
                comment: "费率配置表");

            migrationBuilder.CreateTable(
                name: "ReportStatistic",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "报表统计ID"),
                    ReportType = table.Column<int>(type: "integer", nullable: false, comment: "报表类型(1=日报,2=周报,3=月报)"),
                    ReportDate = table.Column<DateOnly>(type: "date", nullable: false, comment: "报表日期"),
                    ReportPeriod = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false, comment: "报表周期(如:2025-07-01,2025第27周,2025-07)"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户ID"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "门店ID"),
                    PaymentCodeId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "收款码ID"),
                    ReceiptAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "收款金额"),
                    RefundAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "退款金额"),
                    NetAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "净金额(收款-退款)"),
                    DividedAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "分账金额"),
                    SettledAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "结算金额"),
                    ReceiptOrderCount = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "收款订单数"),
                    RefundOrderCount = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "退款订单数"),
                    CustomerCount = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "顾客数"),
                    PaymentMethodStat = table.Column<string>(type: "jsonb", nullable: true, comment: "支付方式统计(JSON格式)"),
                    DiscountStat = table.Column<string>(type: "jsonb", nullable: true, comment: "优惠统计(JSON格式)"),
                    WeeklyComparison = table.Column<string>(type: "jsonb", nullable: true, comment: "近四周收入对比(JSON格式)"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("ReportStatistic_pkey", x => x.Id);
                },
                comment: "报表统计表");

            migrationBuilder.CreateTable(
                name: "SettlementRecord",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "结算记录ID"),
                    SettlementNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "结算记录编号"),
                    SettlementDate = table.Column<DateTime>(type: "timestamp(0) without time zone", nullable: false, comment: "结算日期(只取日期部分时间为 00:00:00)"),
                    SettlementType = table.Column<int>(type: "integer", nullable: false, comment: "结算类型(0=自动,1=手动结算)"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户ID"),
                    TotalActualReceivedAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "总实收金额"),
                    TotalRefundAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "总退款金额"),
                    TotalSettledAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "总结算金额"),
                    Status = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "结算状态(0=结算失败,1=结算成功)"),
                    FailureReason = table.Column<string>(type: "text", nullable: true, comment: "失败原因"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    SettlementCount = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "结算笔数"),
                    RefundCount = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "退款笔数"),
                    TotalDiscountAmount = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "优惠总金额"),
                    DiscountCount = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "优惠笔数"),
                    Commission = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "手续费"),
                    PlatformServiceFee = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "平台服务费")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Settlement_pkey", x => x.Id);
                },
                comment: "结算记录表");

            migrationBuilder.CreateTable(
                name: "Store",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "门店ID"),
                    StoreCode = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "门店编号"),
                    Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "门店名称"),
                    StoreType = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "门店类型"),
                    Address = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "门店地址"),
                    DetailedAddress = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "门店详细地址"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户ID"),
                    ContactPerson = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true, comment: "联系人名称"),
                    ContactPhone = table.Column<string>(type: "character varying(11)", maxLength: 11, nullable: true, comment: "联系电话"),
                    SettlementCycle = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "结算周期"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建人ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改人ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "启用状态"),
                    ThumbnailUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "缩略图Url"),
                    Location = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "经纬度")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Store_pkey", x => x.Id);
                },
                comment: "门店表");

            migrationBuilder.CreateTable(
                name: "Sys_Permission",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "权限ID"),
                    Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "权限名称"),
                    ParentId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "父级权限ID（用于构建权限层级）"),
                    Type = table.Column<int>(type: "integer", nullable: false, comment: "权限类型：1=菜单，2=操作，3=API"),
                    ApiPath = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "API接口路径，仅API类型权限需要"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Sys_Permission_pkey", x => x.Id);
                },
                comment: "系统权限表");

            migrationBuilder.CreateTable(
                name: "Sys_Role",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "系统角色ID"),
                    RoleName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, comment: "角色名称"),
                    RoleType = table.Column<int>(type: "integer", nullable: true, comment: "角色类型(0=平台超管，1=平台管理，2=超管，3=管理，4=监事，5=店长，6=收银员，7=业主，8=招商，9=城市合伙人，10=运营，11=技术，12=会员)"),
                    Description = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "角色描述"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    OrganizationType = table.Column<int>(type: "integer", nullable: true, comment: "组织类型（0=平台，1=商户，2=门店）")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Sys_Role_pkey", x => x.Id);
                },
                comment: "系统角色表");

            migrationBuilder.CreateTable(
                name: "Sys_RolePermission",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联ID"),
                    RoleId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "角色ID"),
                    PermId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "权限ID"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Sys_RolePermission_pkey", x => x.Id);
                },
                comment: "系统角色权限关联表");

            migrationBuilder.CreateTable(
                name: "Sys_User",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "用户Id"),
                    Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "用户名"),
                    Phone = table.Column<string>(type: "character varying(11)", maxLength: 11, nullable: false, comment: "手机号"),
                    Password = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "密码"),
                    Email = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "邮箱"),
                    AvatarUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "用户头像URL"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, comment: "用户状态：0=禁用，1=启用"),
                    LastLoginTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "用户最后登录时间"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    Balance = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "账户余额，单位为分"),
                    BlockedBalance = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "冻结余额，单位为分"),
                    WithdrawableBalance = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "可提现余额，单位为分"),
                    UnsettledBalance = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "未结算余额，单位为分"),
                    DividedBalance = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "待分账余额，单位为分"),
                    CurrentUserRoleId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "用户选择商户团队成员ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Sys_User_pkey", x => x.Id);
                },
                comment: "系统用户表");

            migrationBuilder.CreateTable(
                name: "Sys_UserMiniProgram",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "C端用户ID"),
                    Name = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "用户昵称"),
                    PlatformType = table.Column<int>(type: "integer", nullable: false, comment: "平台类型（1=微信,2=支付宝）"),
                    AppId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "小程序ID"),
                    UnionId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "用户在同一微信开放平台账号下所有应用（包括小程序、公众号等）的全局唯一标识"),
                    OpenId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "用户在当前小程序中的唯一标识"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    IsMain = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否为主小程序"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 1, comment: "启用状态"),
                    Phone = table.Column<string>(type: "character varying(11)", maxLength: 11, nullable: true, comment: "手机号"),
                    Password = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "密码（加密）"),
                    Email = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "邮箱"),
                    AvatarUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "用户头像URL"),
                    LastLoginTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后登录时间"),
                    UserId = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true, comment: "支付宝用户唯一标识")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Sys_UserMiniProgram_pkey", x => x.Id);
                },
                comment: "C端用户表");

            migrationBuilder.CreateTable(
                name: "Sys_UserRole",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "用户角色关联ID（团队成员ID）"),
                    Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "成员昵称"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "用户ID"),
                    RoleId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "角色ID"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "所属商户ID"),
                    StoreId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "所属门店ID"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "并发标记"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    CreatorId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "创建人ID"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    LastModifierId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "最后修改人ID"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, defaultValue: 0, comment: "启用状态"),
                    CodeId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "所属收款码ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("Sys_UserRole_pkey", x => x.Id);
                },
                comment: "系统用户角色关联表");

            migrationBuilder.CreateTable(
                name: "WithdrawalAccount",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "提现账户ID"),
                    AccountType = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "账户类型(0=未定义,1=对公账户,2=法人账户,3=授权对公,4=授权对私)"),
                    RealName = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "真实姓名"),
                    IdentityCard = table.Column<string>(type: "character varying(18)", maxLength: 18, nullable: true, comment: "身份证号"),
                    Address = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "身份证详细地址"),
                    StartDate = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "有效期开始日期"),
                    EndDate = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "有效期结束日期（无限制就不填）"),
                    Bank = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "开户银行名称"),
                    BankBranch = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "开户银行支行名称"),
                    BankAccount = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "银行账号"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, comment: "创建时间"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, comment: "是否删除"),
                    DeleterId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "删除者ID"),
                    DeletionTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "删除时间"),
                    EnableStatus = table.Column<int>(type: "integer", nullable: false, comment: "启用状态"),
                    ActivationStatus = table.Column<int>(type: "integer", nullable: true, comment: "激活状态"),
                    EpaylinksApprovedTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks审核通过时间"),
                    EpaylinksFirstApplyTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks首次申请时间"),
                    EpaylinksLastApplyTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks最后申请时间"),
                    EpaylinksAuditNotificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks审核通知时间"),
                    EpaylinksBusinessNotificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "Epaylinks业务通知时间"),
                    ApproveMessage = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "审核消息")
                },
                constraints: table =>
                {
                    table.PrimaryKey("WithdrawalAccount_pkey1", x => x.Id);
                },
                comment: "提现账户表");

            migrationBuilder.CreateTable(
                name: "WithdrawalRecord",
                columns: table => new
                {
                    Id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "提现记录ID"),
                    UserId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "用户ID"),
                    WithdrawalAccountId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "提现账户ID"),
                    AccountTransactionId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "账户交易记录ID"),
                    Amount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "提现金额"),
                    Fee = table.Column<long>(type: "bigint", nullable: true, defaultValue: 0L, comment: "提现手续费"),
                    FeeRate = table.Column<decimal>(type: "numeric", nullable: true, defaultValueSql: "0", comment: "费率"),
                    ActualAmount = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "实际到账金额"),
                    MerchantId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "商户ID"),
                    Version = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "版本号（3.0）"),
                    CustomerCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "商户编号（平台商户编号）"),
                    OutTradeNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "提现的商户订单号"),
                    MemberId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "分账商户编号"),
                    Protocol = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "绑卡协议号"),
                    PayAmount = table.Column<long>(type: "bigint", nullable: true, comment: "提现金额，单位为分"),
                    ArrivalType = table.Column<int>(type: "integer", nullable: true, comment: "到账类型（默认 0，最大 99；0：当日到账；1：\r\n次日到账，依此类推）"),
                    BankCardId = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true, comment: "银行卡标签"),
                    IsFullAmount = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "是否全额（0：非全额，1：全额\r\n如果 isFullAmount 填了 1，则不管\r\npayAmount 的值）"),
                    ProcedureCustomerCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "手续费扣除商户"),
                    ServiceFee = table.Column<long>(type: "bigint", nullable: true, comment: "商户服务费（单位分，默认 0）"),
                    PayCurrency = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true, comment: "支付币种（默讣 CNY:人民币）"),
                    NotifyUrl = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "异步通知地址"),
                    Remark = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "备注"),
                    Summary = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true, comment: "摘要"),
                    NonceStr = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "随机字符串"),
                    ServiceFeeState = table.Column<int>(type: "integer", nullable: true, comment: "服务费收取状态（1：服务费收取成功，0或null：未收取服务费）"),
                    TransactionNo = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "易票联订单号"),
                    ProcedureFee = table.Column<long>(type: "bigint", nullable: true, comment: "手续费（单位分）"),
                    ActualFee = table.Column<long>(type: "bigint", nullable: true, comment: "实际提现到账金额（单位分，等于提现金额-手续费）"),
                    PayResult = table.Column<string>(type: "character varying(2)", maxLength: 2, nullable: true, comment: "支付结果（00=成功，01=失败，03=处理中，04=延迟处理中）"),
                    ChannelQueryMsg = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "原因说明"),
                    PayTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true, comment: "提现完成时间"),
                    ChannelType = table.Column<string>(type: "character varying(1)", maxLength: 1, nullable: true, comment: "渠道类型（0：门户；1：接口；2：自动提现）"),
                    BankUserName = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true, comment: "收款人姓名"),
                    BankCardNo = table.Column<string>(type: "character varying(34)", maxLength: 34, nullable: true, comment: "银行卡号"),
                    BankName = table.Column<string>(type: "character varying(80)", maxLength: 80, nullable: true, comment: "银行名称"),
                    WithdrawalStatus = table.Column<int>(type: "integer", nullable: true, defaultValue: 0, comment: "系统提现状态（0=处理中，1=成功，2=失败，3=延迟处理中）"),
                    PayState = table.Column<string>(type: "character varying(2)", maxLength: 2, nullable: true, comment: "提现状态（00=成功，01=失败，03=处理中，04=延迟处理中）"),
                    ExtraProperties = table.Column<string>(type: "text", nullable: true, comment: "扩展属性"),
                    CreationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: true, comment: "最后修改时间"),
                    RequestData = table.Column<string>(type: "jsonb", nullable: true, comment: "请求参数JSON"),
                    CallbackData = table.Column<string>(type: "jsonb", nullable: true, comment: "回调参数JSON"),
                    ApiResponse = table.Column<string>(type: "jsonb", nullable: true, comment: "请求后响应JSON"),
                    EpaylinksSplitRecordId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "易票联分账记录ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("WithdrawalRecord_pkey", x => x.Id);
                },
                comment: "提现记录表");

            migrationBuilder.CreateIndex(
                name: "idx_AccountTransaction_UserId",
                table: "AccountTransaction",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "idx_TransactionNo",
                table: "AccountTransaction",
                column: "TransactionNo",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "CouponInstance_InstanceCode_idx",
                table: "CouponInstance",
                column: "InstanceCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "CouponPackage_PackageCode_idx",
                table: "CouponPackage",
                column: "PackageCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "CouponTemplate_TemplateCode_idx",
                table: "CouponTemplate",
                column: "TemplateCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "DividedAgreement_AgreementCode_idx",
                table: "DividedAgreement",
                column: "AgreementCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "DividedAgreement_MerchantId_idx",
                table: "DividedAgreement",
                column: "MerchantId");

            migrationBuilder.CreateIndex(
                name: "DividedAgreementDetail_DividedAgreementId_idx",
                table: "DividedAgreementDetail",
                column: "DividedAgreementId");

            migrationBuilder.CreateIndex(
                name: "DividedAgreementDetail_SubAgreementId_idx",
                table: "DividedAgreementDetail",
                column: "SubAgreementId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "DividedRecord_OrderId_idx",
                table: "DividedRecord",
                column: "OrderId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "idx_DividedRecordNo",
                table: "DividedRecord",
                column: "RecordNo",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "DividedRecordDetail_DividedRecordId_idx",
                table: "DividedRecordDetail",
                column: "DividedRecordId");

            migrationBuilder.CreateIndex(
                name: "DividedRecordDetail_UserId_idx",
                table: "DividedRecordDetail",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_DividedRecordDetail_DividedRecordId_LayerAgreementId",
                table: "DividedRecordDetail",
                columns: new[] { "DividedRecordId", "LayerAgreementId" });

            migrationBuilder.CreateIndex(
                name: "IX_DividedRecordDetail_RootAgreementId",
                table: "DividedRecordDetail",
                column: "RootAgreementId");

            migrationBuilder.CreateIndex(
                name: "IX_DividedRecordDetail_UserId",
                table: "DividedRecordDetail",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "idx_EpaylinksSplitRecord_MerchantId",
                table: "EpaylinksSplitRecord",
                column: "MerchantId");

            migrationBuilder.CreateIndex(
                name: "idx_EpaylinksSplitRecord_OutTradeNo",
                table: "EpaylinksSplitRecord",
                column: "OutTradeNo",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "idx_EpaylinksSplitRecord_RequestTime",
                table: "EpaylinksSplitRecord",
                column: "RequestTime");

            migrationBuilder.CreateIndex(
                name: "idx_EpaylinksSplitRecord_SplitStatus",
                table: "EpaylinksSplitRecord",
                column: "SplitStatus");

            migrationBuilder.CreateIndex(
                name: "idx_EpaylinksSplitRecord_SplitTransactionNo",
                table: "EpaylinksSplitRecord",
                column: "SplitTransactionNo");

            migrationBuilder.CreateIndex(
                name: "idx_EpaylinksSplitRecord_TransactionNo",
                table: "EpaylinksSplitRecord",
                column: "TransactionNo");

            migrationBuilder.CreateIndex(
                name: "idx_EpaylinksSplitRecord_UserId",
                table: "EpaylinksSplitRecord",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "Merchant_MerchantCode_idx",
                table: "Merchant",
                column: "MerchantCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "Order_CreationTime_idx",
                table: "Order",
                column: "CreationTime");

            migrationBuilder.CreateIndex(
                name: "Order_IsSettlement_IsDivided_DividedAgreementId_idx",
                table: "Order",
                columns: new[] { "IsSettlement", "IsDivided", "DividedAgreementId" });

            migrationBuilder.CreateIndex(
                name: "Order_MerchantId_StoreId_CodeId_idx",
                table: "Order",
                columns: new[] { "MerchantId", "StoreId", "CodeId" });

            migrationBuilder.CreateIndex(
                name: "Order_OutTradeNo_idx",
                table: "Order",
                column: "OutTradeNo",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "Order_PaymentStatus_idx",
                table: "Order",
                column: "PaymentStatus");

            migrationBuilder.CreateIndex(
                name: "Order_PayMethod_idx",
                table: "Order",
                column: "PayMethod");

            migrationBuilder.CreateIndex(
                name: "Order_TransactionNo_idx",
                table: "Order",
                column: "TransactionNo");

            migrationBuilder.CreateIndex(
                name: "Orders_OrderCode_idx",
                table: "Order",
                column: "OrderCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "OrderRefundRecord_OrderId_idx",
                table: "OrderRefundRecord",
                column: "OrderId");

            migrationBuilder.CreateIndex(
                name: "OrderRefundRecord_OutRefundNo_idx",
                table: "OrderRefundRecord",
                column: "OutRefundNo",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "OrderRefundRecord_OutTradeNo_idx",
                table: "OrderRefundRecord",
                column: "OutTradeNo");

            migrationBuilder.CreateIndex(
                name: "OrderRefundRecord_TransactionNo_idx",
                table: "OrderRefundRecord",
                column: "TransactionNo");

            migrationBuilder.CreateIndex(
                name: "idx_payment_code",
                table: "PaymentCode",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "PaymentCode_StoreId_MerchantId_idx",
                table: "PaymentCode",
                columns: new[] { "StoreId", "MerchantId" });

            migrationBuilder.CreateIndex(
                name: "IX_AiCollection_PaymentPlatforms_Name",
                table: "PaymentPlatforms",
                column: "Name",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "idx_RateConfig_AmountRange",
                table: "RateConfig",
                columns: new[] { "AmountRangeStart", "AmountRangeEnd" });

            migrationBuilder.CreateIndex(
                name: "idx_RateConfig_EffectiveTime",
                table: "RateConfig",
                column: "EffectiveTime");

            migrationBuilder.CreateIndex(
                name: "idx_RateConfig_MerchantId",
                table: "RateConfig",
                column: "MerchantId");

            migrationBuilder.CreateIndex(
                name: "idx_RateConfig_PaymentPlatformId",
                table: "RateConfig",
                column: "PaymentPlatformId");

            migrationBuilder.CreateIndex(
                name: "idx_RateConfig_Priority",
                table: "RateConfig",
                column: "Priority",
                descending: new bool[0]);

            migrationBuilder.CreateIndex(
                name: "idx_RateConfig_RateType_BusinessType",
                table: "RateConfig",
                columns: new[] { "RateType", "BusinessType" });

            migrationBuilder.CreateIndex(
                name: "idx_RateConfig_StoreId",
                table: "RateConfig",
                column: "StoreId");

            migrationBuilder.CreateIndex(
                name: "idx_ReportPeriod_Merchant",
                table: "ReportStatistic",
                columns: new[] { "ReportPeriod", "MerchantId", "StoreId", "PaymentCodeId", "ReportType" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "idx_SettlementNo",
                table: "SettlementRecord",
                column: "SettlementNo",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "Store_MerchantId_idx",
                table: "Store",
                column: "MerchantId");

            migrationBuilder.CreateIndex(
                name: "Store_StoreCode_idx",
                table: "Store",
                column: "StoreCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "Sys_User_Phone_idx",
                table: "Sys_User",
                column: "Phone",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "Sys_UserRole_UserId_MerchantId_StoreId_idx",
                table: "Sys_UserRole",
                columns: new[] { "UserId", "MerchantId", "StoreId", "CodeId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "idx_WithdrawalRecord_SettlementAccountId",
                table: "WithdrawalRecord",
                column: "WithdrawalAccountId");

            migrationBuilder.CreateIndex(
                name: "idx_WithdrawalRecord_UserId",
                table: "WithdrawalRecord",
                column: "UserId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AccountTransaction");

            migrationBuilder.DropTable(
                name: "ActionLog");

            migrationBuilder.DropTable(
                name: "CouponConsumptionRecord");

            migrationBuilder.DropTable(
                name: "CouponInstance");

            migrationBuilder.DropTable(
                name: "CouponPackage");

            migrationBuilder.DropTable(
                name: "CouponPackageItem");

            migrationBuilder.DropTable(
                name: "CouponPackageReceiveRecord");

            migrationBuilder.DropTable(
                name: "CouponTemplate");

            migrationBuilder.DropTable(
                name: "DividedAgreement");

            migrationBuilder.DropTable(
                name: "DividedAgreementDetail");

            migrationBuilder.DropTable(
                name: "DividedRecord");

            migrationBuilder.DropTable(
                name: "DividedRecordDetail");

            migrationBuilder.DropTable(
                name: "EpaylinksSplitRecord");

            migrationBuilder.DropTable(
                name: "ErrorLog");

            migrationBuilder.DropTable(
                name: "LoginLog");

            migrationBuilder.DropTable(
                name: "Merchant");

            migrationBuilder.DropTable(
                name: "Order");

            migrationBuilder.DropTable(
                name: "OrderRefundRecord");

            migrationBuilder.DropTable(
                name: "PaymentCode");

            migrationBuilder.DropTable(
                name: "PaymentDevices");

            migrationBuilder.DropTable(
                name: "PaymentPlatforms");

            migrationBuilder.DropTable(
                name: "RateConfig");

            migrationBuilder.DropTable(
                name: "ReportStatistic");

            migrationBuilder.DropTable(
                name: "SettlementRecord");

            migrationBuilder.DropTable(
                name: "Store");

            migrationBuilder.DropTable(
                name: "Sys_Permission");

            migrationBuilder.DropTable(
                name: "Sys_Role");

            migrationBuilder.DropTable(
                name: "Sys_RolePermission");

            migrationBuilder.DropTable(
                name: "Sys_User");

            migrationBuilder.DropTable(
                name: "Sys_UserMiniProgram");

            migrationBuilder.DropTable(
                name: "Sys_UserRole");

            migrationBuilder.DropTable(
                name: "WithdrawalAccount");

            migrationBuilder.DropTable(
                name: "WithdrawalRecord");
        }
    }
}
